<template>
	<view><baseForm :column.sync="column" @submitFun="submitFun" :submitStatus="submitDisable"></baseForm></view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import pickerModule from '@/wxcomponents/form/picker.vue';
import { format, dectList } from '@/libs/common.js';
import common from '@/libs/login.js';
import userMixins from '@/libs/userMixins.js'
import formMixins from '@/libs/formMixins.js'
export default {
	mixins: [userMixins, formMixins],
	data() {
		return {
			column: [
				{
					label: '请假人', //输入框title
					name: 'studentNumber', //传值类型
					type: 'normalInput', //输入框类型
					disabled: true, //是否禁用
					required: true, //是否必须填写
					value: '' //输入框的值
				},
				{
					label: '请假类型',
					name: 'leaveType',
					type: 'picker',
					required: true,
					disabled: false,
					value: '',
					text: '请选择请假类型',
					mode: 'selector', //picker的类型
					range: [] //picker的选项集合
				},
				{
					label: '请输入请假原因',
					name: 'leaveReason',
					type: 'normalInput',
					disabled: false,
					required: true,
					value: ''
				},
				
				{
					label: '起始日期',
					value: '',
					required: true,
					name: 'startDate',
					type: 'picker',
					mode: 'date',
					text: '请选择',
					start:format('YY-mm-dd',new Date())
				},
				
				{
					label: '起始时间',
					value: '',
					required: true,
					name: 'startTime',
					type: 'picker',
					mode: 'time',
					text: '请选择',
				},
				{
					label: '结束日期',
					value: '',
					required: true,
					name: 'endDate',
					type: 'picker',
					mode: 'date',
					text: '请选择',
					start:format('YY-mm-dd',new Date())
				},
				{
					label: '结束时间',
					value: '',
					required: true,
					name: 'endTime',
					type: 'picker',
					mode: 'time',
					text: '请选择',
				},
				// {
				// 	label: '请假时间',
				// 	required: true,
				// 	name: 'leaveDays',
				// 	type: 'radio',
				// 	disabled: false,
				// 	value: '1',
				// 	showIndex: false,
				// 	items: [
				// 		{
				// 			value: '1',
				// 			name: '请假时间一日内'
				// 		},
				// 		{
				// 			value: '2',
				// 			name: '请假时间超过一日'
				// 		}
				// 	]
				// },
				// {
				// 	label: '从今天',
				// 	value: '',
				// 	required: true,
				// 	name: 'startTimeIndex',
				// 	type: 'picker',
				// 	mode: 'selector',
				// 	text: '请选择',
				// 	range: []
				// },
				// {
				// 	label: '到今天',
				// 	value: '',
				// 	required: true,
				// 	name: 'endTimeIndex',
				// 	type: 'picker',
				// 	mode: 'selector',
				// 	text: '请选择',
				// 	range: []
				// },
				{
					label: '附件(最多上传三张)',
					type: 'upload',
					url: '/stu/common/uploadFile',
					attachmentVoListStr: '',
					limitSize:3,
					disabled:false
					
				}
			],
			// 课程节次范围
			courseIndexRange: []
		};
	},
	onShow() {
		this.column[0].value = this.user.name;
		this.dictList();
		// this.getCourseNum();
	},
	methods: {
		//获取请假类型,请假时间类型
		async dictList() {
			let resp = await dectList('dict_student_leave_type');
			let leaveDays = await dectList('dict_student_leave_days'); //请假的时间：一天内，或者多天

			this.column[1].range = resp.map(item => {
				return {
					id: item.dictValue,
					name: item.dictName
				};
			});
			// this.column[3].items = leaveDays.map(item => {
			// 	if (item.dictValue == 1) {
			// 		return {
			// 			value: item.dictValue,
			// 			name: '请假时间一日内'
			// 		};
			// 	} else {
			// 		return {
			// 			value: item.dictValue,
			// 			name: '请假时间超过一日'
			// 		};
			// 	}
			// });
		},
		// //获取节次
		// async getCourseNum() {
		// 	let resp = await this.$http.get({
		// 		url: '/edu/term/getCurrentTermInfo',
		// 		data: ''
		// 	});
		// 	let len = resp.result.morningTimes + resp.result.afternoonTimes + resp.result.eveningTimes;
		// 	for (let i = 0; i < len; i++) {
		// 		this.courseIndexRange.push({
		// 			name: `第${i + 1}节课`,
		// 			id: i + 1
		// 		})
		// 	}
		// 	this.column[4].range = this.column[5].range = this.courseIndexRange
		// },
		//提交或修改请假申请
		async submitFun(id) {
			// let leaveDaysStatus = this.column[3].value;
			// let params = {};
			// if (leaveDaysStatus == 1) {
			// 	//此时需要传请假节次
			// 	params = {
			// 		attachmentVoListStr: this.column[7].attachmentVoListStr,
			// 		// leaveDays: leaveDaysStatus, //请假天数
			// 		leaveReason: this.column[2].value,
			// 		leaveType: this.column[1].value,
			// 		startTimeIndex: this.column[4].value,
			// 		endTimeIndex: this.column[5].value,
			// 		studentNumber: this.user.number
			// 	};
			// } else {
			let	params = {
					attachmentVoListStr: this.column[7].attachmentVoListStr,
					// leaveDays: leaveDaysStatus, //请假天数
					leaveReason: this.column[2].value,
					leaveType: this.column[1].value,
					startTime: `${this.column[3].text} ${this.column[4].text}`,
					endTime: `${this.column[5].text} ${this.column[6].text}`,
					studentNumber: this.user.number
				};
			// }
			let rules = [
				{
					key: 'leaveType',
					checkFunc(value) {
						if (!value)	return false;
						return true;
					},
					errMsg: '请选择请假类型'
				},
				{
					key: 'leaveReason',
					checkFunc(value) {
						if (!value)	return false;
						return true;
					},
					errMsg: '请输入请假原因'
				}
			]
			let checkRes = this.checkFormIsPassRules(params, rules);
			if (!checkRes.isPass) {
				uni.showToast({
					title: checkRes.errMsg,
					icon: 'none',
					duration: 2000,
				});
				return;
			}
			// 自定义判断请假时间的完整性
			if (!this.column[4] || !this.column[5]) {
				uni.showToast({
					title: '请选择请假时间',
					icon: 'none',
					duration: 2000,
				});
				return;
			} 
			let resp = await this.$http.post({
				url: '/stu/studentLeave/save',
				data: params
			})
			this.showToast('提交成功',()=> {uni.navigateBack()});
		}
	},
	components: {
		baseForm,
		pickerModule
	},
	computed: {
		columnTime() {
			return this.column[3].value;
		}
	},
	watch: {
		// columnTime: {
		// 	async handler(n, o) {
		// 		let timeSelectStart = {
		// 			label: '从今天',
		// 			value: '',
		// 			required: true,
		// 			name: 'startTimeIndex',
		// 			type: 'picker',
		// 			mode: 'selector',
		// 			text: '请选择',
		// 			range: this.courseIndexRange
		// 		};
		// 		let timeSelectEnd = {
		// 			label: '到今天',
		// 			value: '',
		// 			required: true,
		// 			name: 'endTimeIndex',
		// 			type: 'picker',
		// 			mode: 'selector',
		// 			text: '请选择',
		// 			range: this.courseIndexRange
		// 		};
		// 		let dateSelectStart = {
		// 			label: '开始',
		// 			value: format('YY-mm-dd', new Date()),
		// 			required: true,
		// 			name: 'startTime',
		// 			type: 'picker',
		// 			mode: 'date',
		// 			text: format('YY-mm-dd', new Date())
		// 		};
		// 		let dateSelectEnd = {
		// 			label: '结束',
		// 			value: format('YY-mm-dd', new Date()),
		// 			required: true,
		// 			name: 'endTime',
		// 			type: 'picker',
		// 			mode: 'date',
		// 			text: format('YY-mm-dd', new Date())
		// 		};

		// 		if (n == 1) {
		// 			this.column.splice(4, 2, timeSelectStart, timeSelectEnd);
		// 		} else {
		// 			this.column.splice(4, 2, dateSelectStart, dateSelectEnd);
		// 		}
		// 	}
		// 	// immediate: true, // 立即去执行
		// 	// deep: true //深度监听
		// }
	}
};
</script>

<style></style>
